// tests/bigint_tests.cpp
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <sstream>

#include "bigintaddsub.h"

TEST(BigIntStep1, DefaultIsZero) {
    BigInt value;
    std::ostringstream oss;
    oss << value;
    EXPECT_EQ("0", oss.str());
}

TEST(BigIntStep2, ParseSignedString) {
    BigInt positive("+123");
    BigInt negative("-045");
    BigInt mixed(" 9a8");

    std::ostringstream oss;
    oss << positive;
    EXPECT_EQ("123", oss.str());

    oss.str(std::string());
    oss.clear();
    oss << negative;
    EXPECT_EQ("-45", oss.str());

    oss.str(std::string());
    oss.clear();
    oss << mixed;
    EXPECT_EQ("98", oss.str());
}

TEST(BigIntStep3, ConstructFromLongLong) {
    BigInt pos(42LL);
    BigInt neg(-9000LL);
    BigInt zero(0LL);

    std::ostringstream oss;
    oss << pos;
    EXPECT_EQ("42", oss.str());

    oss.str(std::string());
    oss.clear();
    oss << neg;
    EXPECT_EQ("-9000", oss.str());

    oss.str(std::string());
    oss.clear();
    oss << zero;
    EXPECT_EQ("0", oss.str());
}

TEST(BigIntStep4, AdditionSameSign) {
    BigInt sum1("123");
    BigInt sum2("877");
    BigInt sum3("-100");
    BigInt sum4("-900");

    EXPECT_EQ("1000", (sum1 + sum2).toString());
    EXPECT_EQ("-1000", (sum3 + sum4).toString());
}

TEST(BigIntStep5, AdditionDifferentSign) {
    BigInt a("1000");
    BigInt b("-1");
    BigInt c("-200");
    BigInt d("50");

    EXPECT_EQ("999", (a + b).toString());
    EXPECT_EQ("-150", (c + d).toString());
    EXPECT_EQ("999", (b + a).toString());
}

// Step6: 验证减法通过加法复用实现
TEST(BigIntStep6, Subtraction) {
    BigInt a("1000");
    BigInt b("1");
    BigInt c("-500");
    BigInt d("100");

    EXPECT_EQ("999", (a - b).toString());
    EXPECT_EQ("-600", (c - d).toString());
    EXPECT_EQ("600", (d - c).toString());
}

/**
 * @brief gtest 入口。
 */
int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}